<template>
    <div>
        <el-form label-width="85px" :model="Document" ref="Document_refs">
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="文档编号" prop="ContractNumber">
                        <el-input v-model="Document.DocumentNumber"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="文档名称" prop="Title">
                        <el-input v-model="Document.Title"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="可见级别" prop="FileSeeType">
                        <el-select v-model="Document.FileSeeType" style="width: 100%">
                            <el-option label="高层" :value="1"></el-option>
                            <el-option label="中高层" :value="2"></el-option>
                            <el-option label="全员" :value="4"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="文件类型" prop="FileType">
                        <el-select v-model="Document.FileType" style="width: 100%">
                            <el-option label="规章制度" :value="8"></el-option>
                            <el-option label="模板文件" :value="16"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="文件描述" prop="FileDescript">
                        <el-input v-model="Document.FileDescript"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="备注" prop="Remark">
                        <el-input v-model="Document.Remark"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="文档">
                        <el-row >
                            <el-col :span="11">
                                <UploadFileF ref="UploadFileF_UpdataDocument"
                                             :multiple="false"
                                             :another-data="AnotherData"
                                             :showfilelist="true"
                                             :upshow="false"
                                             content="重新上传"
                                             btnsize="medium"></UploadFileF>
                            </el-col>
                            <el-col :offset="2" :span="11">
                                <el-button type="warning" size="medium" style="width: 100%" @click="enclosure_down(Document)">下载合同</el-button>
                            </el-col>
                        </el-row>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col align="center">
                    <el-button type="success" @click="UpdataDocument_event">修改文档</el-button>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>
    import * as publicjs from "../../../public/Scriput/Public";
    import UploadFileF from "../UploadFileF";
    import * as IsExistjs from "../../../public/Scriput/IsExist";

    export default {
        name: "UpdataDocument",
        components: {
            UploadFileF
        },
        props: {
            Document_Template: {
                type: Object,
                required: true,
            }
        },
        watch: {
            Document_Template: function (val) {
                this.init(val)
            }
        },
        created() {
            this.init(this.Document_Template)
            IsExistjs.IsExist.http(this.$http, this.$message)
        },
        data() {
            return {
                //文件上传参数
                AnotherData: {
                    FileType: 4,
                    id: 0,
                    Type: 0,
                    Single: true,
                },
                Document: {},
            }
        },
        methods: {
            init(obj) {
                let newobj = JSON.parse(JSON.stringify(obj))
                this.Document = newobj
            },
            async UpdataDocument_event() {
                let result = await IsExistjs.IsExist.IsExistDocumentNumber(this.Document.DocumentNumber)
                if (this.$refs['UploadFileF_UpdataDocument'].fileList.length > 0) {
                    this.Document.FileName = this.$refs['UploadFileF_UpdataDocument'].fileList[this.$refs['UploadFileF_UpdataDocument'].fileList.length - 1].name
                }
                if (this.Document_Template.DocumentNumber == this.Document.DocumentNumber || !result) {
                    let loadding = this.openLoading();
                    this.$http.post('Document/UpdateDocumentContent', this.Document).then(res => {
                        loadding.close();
                        if (res.data) {
                            this.$message.success('修改成功')
                            this.$parent.$parent.formdata()
                            this.$parent.$parent.UpdataDocument_dialog.dialog = false
                            this.AnotherData.id = this.Document.Id
                            this.AnotherData.FileType = this.Document.FileType
                            if (this.$refs['UploadFileF_UpdataDocument'].fileList.length > 0) {
                                this.$refs['UploadFileF_UpdataDocument'].submitUpload()
                            }
                        } else {
                            this.$message.warning('修改失败')
                        }
                    })
                } else {
                    this.$message.warning('文档编号已存在')
                }
            },
            //文件下载
            enclosure_down(obj) {
                let option = { id: obj.Id, FileType: obj.FileType, Type: 0, FileName: obj.FileName }
                publicjs.DownLoadFile(option)
            }
        }
    }
</script>

<style scoped>

</style>
